package com.sc.key;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Formatter;
import java.util.Locale;

public class KeyContent {

	public static void main(String[] args) throws Exception {
		//获取ip地址
		InetAddress address =InetAddress.getLocalHost();
		String ipAddr = address.getHostAddress();
		//获取mac地址
		byte[] mac = NetworkInterface.getByInetAddress(address).getHardwareAddress();
		String macAddr = ""; 
        Formatter formatter = new Formatter(); 
        for (int i = 0; i < mac.length; i++) { 
        	macAddr = formatter.format(Locale.getDefault(), "%02X%s", mac[i], 
        			(i < mac.length - 1) ? "-" : "").toString(); 

        }
        formatter.close();
		
		System.out.println("ip："+ipAddr);
		System.out.println("mac："+macAddr);
		
		//生成公钥和私钥
		KeyGenerater keyGenerater = new KeyGenerater();
		keyGenerater.generater(ipAddr,macAddr,"zzwbkj2014");

		//生成签名
		byte[] priSign = Signaturer.sign(keyGenerater.getPriKey(), "zzwbkj2014");
		System.out.println("priSign = "+new String(priSign));
		
		boolean result = SignProvider.verify(keyGenerater.getPubKey(), "zzwbkj2014", priSign);
		System.out.println("通过："+result);
	}

}
